因為資料量太大,所以我寫完code之後決定交給別人執行。
這時候會有一個問題,R語言本身功能不多,是一個需要函式你去下載包裝(install.packages)的軟體,所以大部分人安裝的packages不同,要交給別人執行程式的時候就需要讓他的電腦也安裝你需要的程式。
一般人的做法就是打上install.packages()或是點右下角的packages的install,然後打上需要安裝的程式,多少會造成執行上不能一個RUN就執行完成的問題。
因此,如果你在你的程式語言前打上
packages = c("readxl")
existing = as.character(installed.packages()[,1])
for(pkg in packages[!(packages %in% existing)]) install.packages(pkg)
就可以一鍵執行啦!而且也不會因為全部都打install.packages讓程式執行不必要的東西,執行起來也是特別的緩慢。
例如:
packages = c(
"readxl","data.table","ggplot2","lubridate","grid","xlsx","stringr","dplyr",
"grid","ggrepel","plotly","tmcn","tidyverse","showtext","shiny","shinydashboard",
"shinycssloaders","ggthemes","rgeolocate","leaflet","leafletCN","scales","magrittr")
existing = as.character(installed.packages()[,1])
for(pkg in packages[!(packages %in% existing)]) install.packages(pkg)